<!DOCTYPE html>
<!-- <html lang="en" dir="rtl"> -->
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {margin: 0;overflow: hidden;}
    #canvas {background-color: antiquewhite;}
  </style>
</head>
<body>
  <canvas id="canvas"></canvas>
  <script>
    /** @type {HTMLCanvasElement} */
    const canvas = document.querySelector('#canvas');
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;
    const ctx = canvas.getContext('2d');

    ctx.beginPath();
    ctx.strokeStyle = '#999';
    ctx.setLineDash([8]);
    ctx.moveTo(300,50);
    ctx.lineTo(300,600);
    ctx.stroke();

    ctx.font = '36px Arial';

    /*
      textAlign
      start: 基于文本起始位对齐，默认
      end: 基于文本结束位对齐
      left: 左对齐
      right: 右对齐
      center: 居中对齐
    */
   ctx.textAlign = 'start'
   ctx.fillText('start', 300, 100);

   ctx.textAlign = 'end'
   ctx.fillText('end', 300, 150);

   ctx.textAlign = 'left'
   ctx.fillText('left', 300, 200);

   ctx.textAlign = 'right'
   ctx.fillText('right', 300, 250);

   ctx.textAlign = 'center'
   ctx.fillText('center', 300, 300);

  </script>
</body>
</html>